package com.zzs.astar;

import java.util.Objects;

/**
 * 为了实现AStar算法构建的实体类
 * 包含：
 *      基本数据entity
 *      确定路径长度g
 *      估算路径长度h
 *      前驱节点parent
 */
public class Node {
    Entity entity;
    int g;
    int h;
    Node parent;

    public Node(Entity entity, int g, int h, Node parent) {
        this.entity = entity;
        this.g = g;
        this.h = h;
        this.parent = parent;
    }

    public int f(){
        return g + h;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Node node = (Node) o;
        return Objects.equals(entity, node.entity);
    }

    @Override
    public int hashCode() {
        return Objects.hash(entity);
    }
}
